var fade_id = 5;
var loop_id_t;
var fade_id_t;
var opacity=100;
var change_interval = 5000;

function set_opacity (obj, opacity) {
	obj.style.opacity = opacity/100;
	obj.style.filter = 'alpha(opacity=' + opacity + ')';
}

function section_fade_out () {
	opacity = opacity - 1;
	var img = document.getElementById("section_header_image_" + fade_id);
	img.style.zIndex = 2;
	set_opacity (img, opacity);	
	
	var next_id = fade_id + 1;
	var next_img = document.getElementById("section_header_image_" + next_id);
	if (next_img == null) {
		next_id = 0;
		next_img = document.getElementById("section_header_image_" + next_id);
	}
	next_img.style.zIndex = 1;
	set_opacity (next_img, 100);
	
	if (opacity <= 0) {
		opacity = 100;
		img.style.zIndex = 0;
	} else fade_id_t = setTimeout("section_fade_out ()",1);
}

function section_fade_through () {
	
	fade_id++;
	
	var img = document.getElementById("section_header_image_" + fade_id);
	if (img == null) fade_id = 0;
	console.log(fade_id);
	section_fade_out ();
	
	fade_id_t = setTimeout("section_fade_through ()",change_interval);
}
function start_fades () {
	section_fade_through ();
}

start_fades ();
//var loop_t = setTimeout("start_fades ()",change_interval);